import { _mirror } from "../../math/mirror.js"
import { polarPoints } from "../../math/points/index.js"
import { pointsPath } from "../path.js";

export const hexaflakePoints = (options) => {
    let { o = [300, 200], r = 200, n = 3, depth = 3, a = 0, k = 1 } = options


    let result = []
    let _iter = (o, r, n, a, depth) => {
        if (depth === 0) {
            let points = polarPoints({
                o, r, n, a
            })
            result.push(...points)
            points.forEach(t => {
                result.push(..._mirror(points, t))
            })
        } else {
            let points = polarPoints({
                o, r, n, a
            })
            points.forEach(t => {
                let o2 = _mirror(t, o)
                _iter(o2, r / 3, n, a, depth - 1)
            })
        }
    }

    _iter(o, r, n, a, depth)
    return result
}

export const hexaflake = (options, props) => {
    let stps = hexaflakePoints(options)
    let { n } = options
    return pointsPath({
        points: stps,
        closed: false,
        broken: n
    }, props)
}